package com.javasm.controller;


import com.javasm.common.http.AxiosResult;
import com.javasm.common.page.PageResult;
import com.javasm.controller.base.BaseController;
import com.javasm.domin.criteria.AftersaleAppealCriteria;
import com.javasm.domin.entity.AftersaleAppeal;
import com.javasm.domin.entity.AftersaleB2cChange;
import com.javasm.domin.vo.AftersaleAppealVo;
import com.javasm.service.AftersaleAppealService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author whl
 * @since 2022-01-13
 */
@RestController
@RequestMapping("aAppeal")
@RequiredArgsConstructor//和@Autowired效果一样
public class AftersaleAppealController extends BaseController {

    private final AftersaleAppealService aftersaleAppealService;

    /**
     * 添加
     *
     * @param aftersaleEnter
     * @return
     */
    @PostMapping
    public AxiosResult<Void> add(@RequestBody AftersaleAppeal aftersaleAppeal) {
        LocalDateTime sj = LocalDateTime.now();
        aftersaleAppeal.setAppealTime(sj);
        return toAxios(aftersaleAppealService.save(aftersaleAppeal));
    }

    /**
     * 制单修改
     *
     * @param aftersaleEnter
     * @return
     */
    @PutMapping
    public AxiosResult<Void> update(@RequestBody AftersaleAppeal aftersaleAppeal) {
        return toAxios(aftersaleAppealService.update(aftersaleAppeal));
    }


    /**
     * 审批修改
     *
     * @param aftersaleOut
     * @return
     */
    @PutMapping("sp")
    public AxiosResult<Void> updatesp(@RequestBody AftersaleAppeal aftersaleAppeal) {
        LocalDateTime sj = LocalDateTime.now();
        aftersaleAppeal.setApproverTime(sj);
        return toAxios(aftersaleAppealService.update(aftersaleAppeal));
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public AxiosResult<Void> delete(@PathVariable Long id) {
        return toAxios(aftersaleAppealService.deleteById(id));
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public AxiosResult<AftersaleAppeal> findById(@PathVariable Long id) {
        AftersaleAppeal byId = aftersaleAppealService.getById(id);
        return AxiosResult.success(byId);
    }

    /**
     * 分页条件查询
     */
    @GetMapping
    public AxiosResult<PageResult<AftersaleAppealVo>> list(AftersaleAppealCriteria aftersaleAppealCriteria) {
        //分页条件查询
        return AxiosResult.success(aftersaleAppealService.searchPage(aftersaleAppealCriteria));

    }

    /**
     * 批量删除
     */

    @DeleteMapping("batch/{ids}")
    public AxiosResult<Void> batchDelete(@PathVariable List<Long> ids) {
        return toAxios(aftersaleAppealService.batchDeleteByIds(ids));
    }


}
